-- encounter_monster
-- created by chendh
-- 遭遇怪格子规则

return {
    -- 还原格子
    restoreGrid = function(grid, info)
        local monster = grid.monster;
        if info.class_id then
            monster.classId = info.class_id;

            local dbase = {
                ["class_id"] = info.class_id,
                ["skills"]   = MonsterM.query(info.class_id, "skills"),
            };

            monster.dbase:aborb(dbase);

            -- 重刷下属性
            PropM.refresh(monster);
        end

        -- 还原
        monster:restoreInfo(info);

        if info.bonus and info.bonus.e then
            grid.bonus = info.bonus:toTable();
        else
            grid.bonus = info.bonus;
        end
    end,

    -- 收集上下文
    collectContext = function(grid)
        -- 需要收集当前的属性、血量，复活标记
        local monster = grid.monster;

        -- 收集信息
        local ret = monster:collectInfo();

        -- 如果怪物已经死亡了
        if monster:isDead() then
            ret.state = GRID_STATE_DISABLE;
            ret.is_dead = 1;
        end

        if grid.bonus then
            ret.bonus = grid.bonus;
        end

        return ret;
    end
};
